<?php
class ArrayToxml
{
	public static $xml;

	public static function array2xml($array){
		self::$xml=self::array2xml_do($array);       
	}

	public static function array2xml_do($array){
		$xml="";
		foreach($array as $key=>$val){
			is_numeric($key) && $key="item id=\"$key\"";
			$xml.="<$key>";
			$xml.=is_array($val) ? self::array2xml_do($val) : $val;
			list($key) = explode(' ',$key);
			$xml.="</$key>\n";
		}
		return $xml;
	}

	public static function get_xml(){
		return self::$xml;
	}

	//------------------------------------------------------------

	public static function gen_xml_file($arr){
		self::array2xml($arr);
		$str=self::get_xml();

		$str=str_replace(array('banner_0','banner_1','banner_2','banner_3','banner_4'),'banner',$str);
		$str=str_replace("<description>", "<description>\n<![CDATA[\n", $str);
		$str=str_replace("</description>", "\n]]>\n</description>", $str);

		$str=str_replace("<name>", "<name>\n<![CDATA[\n", $str);
		$str=str_replace("</name>", "\n]]>\n</name>", $str);

$head="<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<umiwi>
	<banners interval=\"3000\">
";
		$str=$head.$str."</banners></umiwi>";
		
		//$file=$_SERVER["DOCUMENT_ROOT"]."/flash/umiwi.xml";
		$file=WEBROOT."flash/umiwi.xml";
		file_put_contents($file,$str);
	}
}